﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Project_CPU.GenerateData
{
    public class DateFormat
    {
        static string parametr;

        public static void DefinitionFormatOfDate(DateTime DateTimeFrom, DateTime DateTimeTo)
        {
            TimeSpan interval = DateTimeTo - DateTimeFrom;
            string res = "";
            TimeSpan x = new TimeSpan(29, 0, 0, 0); //29 days, hours, minutes, seconds

            if (TimeSpan.Compare(interval, x) < 0)//interval <= 30 days
            {
                x = new TimeSpan(1, 0, 0, 0);
                if (TimeSpan.Compare(interval, x) <= 0) //interval <= 1 day
                {
                    x = new TimeSpan(0, 1, 0, 0);
                    if (TimeSpan.Compare(interval, x) <= 0) //interval <= 1 hour
                    {
                        x = new TimeSpan(0, 0, 1, 0); //days, hours, 1 minutes, seconds
                        if (TimeSpan.Compare(interval, x) <= 0) //interval < x.minutes=1
                        {
                            if (Equals(DateTimeFrom.Minute, DateTimeTo.Minute))
                                res = "second"; //<=1 mitue - seconds
                            else
                                res = "minutesecond";  //>1 minute, <=1 hour - minutesecond

                        }
                        else
                        {
                            res = "time";  //>1 minute, <=1 hour - time // Georgiy, I don't believe that you really will be reading this) But Hello, if you do) and sorry for my terrible english
                        }
                    }
                    else
                    {
                        if (Equals(DateTimeFrom.Day, DateTimeTo.Day))
                            res = "time"; //  <=1 day, >1 hour - time
                        else
                            res = "datetime"; //  <=1 day, >1 hour - datetime
                    }
                }
                else
                {
                    res = "datetime"; //  <29 days, >1 day - datetime
                }
            }
            else
            {
                res = "date"; //  >=29 days - date
            }

            parametr = res;
        }

        public static string ReturnNameOfMonth(int number)
        {
            string[] namesEn = new string[] { "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" };
            string[] namesRu = new string[] { "янв", "фев", "март", "апр", "мая", "июня", "июля", "авг", "сен", "окт", "ноя", "дек" };
            return namesRu[number - 1];

        }

        public static string ReturnDateInString(DateTime InputDateTime)
        {
            string res = "";

            if (parametr == "second")
            {
                res = InputDateTime.Second.ToString() + " sec";
            }
            if (parametr == "timesecond")
            {
                res = InputDateTime.ToShortTimeString() + ":" + InputDateTime.Second.ToString();
            }
            if (parametr == "minutesecond")
            {
                res = InputDateTime.Minute.ToString() + " min " + InputDateTime.Second.ToString() + " sec";
            }

            if (parametr == "time")
            {
                res = InputDateTime.ToShortTimeString();
            }

            if (parametr == "datetime")
            {
                res = InputDateTime.Day.ToString() + " " + ReturnNameOfMonth(InputDateTime.Month) + " " + InputDateTime.ToShortTimeString();
            }

            if (parametr == "date")
            {
                res = InputDateTime.Day.ToString() + " " + ReturnNameOfMonth(InputDateTime.Month);
            }

            return res;
        }



    }
}